<?php
/*
 * emarket - a website to create your own online-shop.  
 * Copyright (C) 2009  Frédéric Delorme
 *
 * This file is part of emarket.
 *
 * emarket is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * emarket is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with emarket.  If not, see <http://www.gnu.org/licenses/>.
 *
 * To contact me: frederic.delorme@gmail.com
 * to see some information on te project : http://code.google.col/p/os-emarket/
 *
 */
global $framework;
require_once("webapp/application/application.php");
require_once("webapp/helpers/cart.helpers.php");
require_once("$framework/paginator.php");
require_once("$framework/session.php");

/**
 * Post management class. Allow create, retrieve, update, and delete of post entity, 
 * according to user rights.  
 * @author delormef
 *
 */
class PostManager extends Application{
	/**
	 * <p>Posts attributes contains array of post currently managed by this class.</p>
	 * @var array() of Post.
	 */
	protected $posts;
	/**
	 * (non-PHPdoc)
	 * @see framework/WebApp#initialize()
	 */
	public function initialize(){
		__debug(__CLASS__."::initialize() - start",__FILE__, __LINE__);
		$this->addEntity(
			'post',
			__query_entities(
				"post",
					$where = "",
					$order = array( array('field'=>"created_at",'comparator'=>"ASC")),
					$limit = ""
				)
			);
		__template_set('posts',self::$_entities['post']);	
		__debug(__CLASS__."::initialize() - end",__FILE__, __LINE__);
	}
	/**
	 * Display list of posts according to the category $id input.
	 * @param $type must be post.
	 * @param $id category identifier to filter posts.
	 * @return unknown_type
	 */
	public function lister($type,$id){
		__debug(__CLASS__."::lister() - start : type=$type, id=$id",__FILE__, __LINE__);
		$this->setEntity(
			'post',
			__query_entities(
				"post",
					$where = array( array('field'=>"category_id",'comparator'=>"=",'value'=>$id)),
					$order = array( array('field'=>"created_at",'comparator'=>"ASC")),
					$limit = ""
				)
			);
		__template_set('posts',self::$_entities['post']);
		
		__debug(__CLASS__."::lister() - end",__FILE__, __LINE__);
		return "entities/post/list";		
	}
	
	public function show($type, $id){
		__debug(__CLASS__."::lister() - start : type=$type, id=$id",__FILE__, __LINE__);
		
	}
}
?>